<template>
    <rx-dialog @ok="handleSubmit" @cancel="cancel">
        <rx-layout>
            <template #middle>
                <div style=" height: 100%; padding: 20px;">
                    <a-form layout="vertical">
                        <a-form-item :label="filterI18n('title','标题')">
                            <a-input v-model:value="title" style="width: 100%"></a-input>
                        </a-form-item>
                        <a-form-item :label="filterI18n('dateFormat','日期格式')">
                            <a-select :placeholder="filterI18n('dateFormat','日期格式')"
                                      :options="dateFormats" v-model:value="settings.format"></a-select>
                        </a-form-item>
                        <a-form-item :label="filterI18n('defaultValues','默认值')">
                            <a-date-picker
                                :locale="locale"
                                style="width: 100%"
                                @change="dateChange"
                                :show-time="settings.format!='YYYY-MM-DD'"
                                :format="settings.format || 'YYYY-MM-DD'"
                                v-model:value="date"
                            />
                        </a-form-item>
                    </a-form>
                </div>
            </template>
        </rx-layout>
    </rx-dialog>
</template>

<script>
import filter from "./filter.js";
import dayjs from "dayjs";
import 'dayjs/locale/zh-cn';
dayjs.locale('zh-cn');
import locale from 'ant-design-vue/es/date-picker/locale/zh_CN';
export default {
    name: "date-filter",
    mixins:[filter],
    data() {
        return {
            dateFormats:[
                {value:'YYYY-MM-DD',label:'YYYY-MM-DD'},
                {value:'YYYY-MM-DD HH:mm:00',label:'YYYY-MM-DD HH:mm:00'},
                {value:'YYYY-MM-DD HH:mm',label:'YYYY-MM-DD HH:mm'},
                {value:'YYYY-MM-DD HH:mm:ss',label:'YYYY-MM-DD HH:mm:ss'}
            ],
			date:"",
            locale
        }
    },
    methods: {
		filterI18n(name,text,key){
			return this.$ti18(name,text,"filterControllerLang",key);
		},
        //初始化配置
        initSetting() {
            if(this.row.settings){
                this.settings =this.row.settings;
                if(this.row.value){
					this.date=dayjs(this.row.value,this.settings.format||'YYYY-MM-DD');
				}
            }else {
                this.settings = {
                    format:"YYYY-MM-DD"
                }
            }
        },
		dateChange(value) {
            if(!value){
                this.defValue='';
            }else {
                this.defValue = dayjs(value).format( this.settings.format || 'YYYY-MM-DD');
            }
		},
    },
    watch: {
    }
}
</script>

<style scoped>
</style>
